package com.whj.wkpt.mapper;

import com.whj.wkpt.entity.TaskApplication;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TaskApplicationMapper {
    
    TaskApplication findById(Long applicationId);
    
    @Insert("INSERT INTO task_applications(task_id, freelancer_id, apply_time, delivery_time, delivery_status, create_time, update_time) " +
            "VALUES(#{taskId}, #{freelancerId}, #{applyTime}, #{deliveryTime}, #{deliveryStatus}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "applicationId")
    int insert(TaskApplication taskApplication);
    
    @Update("UPDATE task_applications SET task_id=#{taskId}, freelancer_id=#{freelancerId}, apply_time=#{applyTime}, " +
            "delivery_time=#{deliveryTime}, delivery_status=#{deliveryStatus}, update_time=#{updateTime} " +
            "WHERE application_id=#{applicationId}")
    int update(TaskApplication taskApplication);
    
    @Delete("DELETE FROM task_applications WHERE application_id = #{applicationId}")
    int deleteById(Long applicationId);
    
    List<TaskApplication> findAll();
    
    List<TaskApplication> findByTaskId(Long taskId);
    
    List<TaskApplication> findByFreelancerId(Long freelancerId);
    
    List<TaskApplication> findByDeliveryStatus(String deliveryStatus);
    
    List<TaskApplication> findByTaskIdAndDeliveryStatus(Long taskId, String deliveryStatus);
    
    List<TaskApplication> findByTaskIds(List<Long> taskIds);
}